/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
package com.wealth.coupon.web.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wealth.coupon.entity.CouponRecord;
import com.wealth.coupon.service.ICouponRecordService;
import com.wealth.system.service.ShiroUser;
import com.wealth.system.web.controller.BaseController;

import iaas.web.JqGridRequest;
import iaas.web.JqGridResponse;
import iaas.web.JqGridUtil;

/**
 * @author chan
 * @version 1.0
 * @since 1.0
 */

@Controller
@RequestMapping(value = "/manage/coupon/couponRecord")
public class CouponRecordController extends BaseController {

	Logger logger = Logger.getLogger(CouponRecordController.class);

	@Autowired
	private ICouponRecordService recordService;

	/**
	 * 列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(Model model) {
		Long corpid = ShiroUser.getInstance().getUser().getCorp().getId();
		model.addAttribute("corpid", corpid);
		return "coupon/couponRecord/list";
	}

	/**
	 * 列表ajax查询数据
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public JqGridResponse getJson(Model model, JqGridRequest request) {
		try {

			Long corpid = ShiroUser.getInstance().getUser().getCorp().getId();

			Page<CouponRecord> page = recordService.get(corpid, request, CouponRecord.class);

			return JqGridUtil.getJqGrirdResponse(page);
		} catch (Exception e) {
			logger.error("列表错误！", e);
			return null;
		}
	}

}